from django.shortcuts import render, reverse, redirect
from django.http import HttpResponse, JsonResponse
# Create your views here.


def home(req):
    return render(req, 'home.html')


def hello_user(req, user_name):
    context = {
        'user': user_name
    }
    return render(req, "hello.html", context=context)


def hello_defualt(req):
    return redirect(reverse('users:hello_user', args=("Toby_HUANG",)))


def get_data(req, user_name):
    return JsonResponse(
        {"edu": user_name+"'s CSDN学院"},
        json_dumps_params={"ensure_ascii": False}
    )


def frontend(req):
    return render(req, "frontend.html", context={
        "user": "Toby HUANG",
        "ids": list(range(1, 10, 3)),
        "user_obj": {
            "name": "Toby HUANG",
            "age": "22",
        }
    })
